*cd "/Users/sanchariroy/Google Drive/Sanchari_F/DBW/data/prepared_data/"
*cd "/Users/bsog0079/Dropbox/DBW/agencytrainingpaper/ReSTAT_revisions/prepared_data"
cd "/Users/sr432/Google Drive/Sanchari_F/DBW/data/prepared_data_dropbox/"


use medium_term_admin_health_data, clear

set more off

/*** This do file contains the code for the following Tables:
Main Tables: 6 (columns 2 and 3)
Appendix Tables: A18 (columns 2, 3, 5 and 6)
***/

********************************************************************************
***REGRESSIONS: MEDIUM TERM/NONSELF-REPORTED HEALTH OUTCOMES********************
********************************************************************************

/**Table 6**/
 
eststo clear

*Col 2
eststo reg1: reg visitdum1 treat visitdum1_bline i.areacode if visitnum==4
ritest treat _b[treat], reps(1000) seed(125): `e(cmdline)'
matrix pvalues=r(p)
mat colnames pvalues = treat
est restore reg1

estadd matrix pvalues = pvalues

*Col 3
eststo reg2: reg visitdum1 treat visitdum1_bline i.areacode if post==1
ritest treat _b[treat], reps(1000) seed(125): `e(cmdline)'
matrix pvalues=r(p)
mat colnames pvalues = treat
est restore reg2

estadd matrix pvalues = pvalues

esttab using maintables.rtf, append se title(Table 6: Program Impact on Health-Seeking Behaviour, ANCOVA) cells(b(star fmt(2)) se(par fmt(2)) pvalues(par([ ]))) keep(treat visitdum1_bline) order(treat visitdum1_bline) label starlevels(* 0.10 ** 0.05 *** 0.01) stats(r2_a N, fmt(2 0) label("Adj. R-sq" "N"))


/**Appendix Table A18**/

eststo clear

*endline

*Col 2
eststo: reg visitdum1 treat i.areacode if visitnum==4
*Col 3
eststo: reg visitdum1 treat i.areacode if post==1

*diff-in-diff

*Col 5
eststo: reg visitdum1 treat post1 treatpost1 i.areacode
*Col 6
eststo: reg visitdum1 treat post treatpost i.areacode

esttab using appendtables.rtf, append se title(Appendix Table A18: Program Impact on Health-Seeking Behaviour, Endline and Diff-in-Diff) cells(b(star fmt(2)) se(par fmt(2)) pvalues(par([ ]))) keep(treat post1 treatpost1 post treatpost) order(treat post1 treatpost1 post treatpost) label starlevels(* 0.10 ** 0.05 *** 0.01) stats(r2_a N, fmt(2 0) label("Adj. R-sq" "N"))

*non-parametric plotting over time

ta visitnum, ge(visitno)

forval i=1/10 {
ge treatvisitno`i'=treat*visitno`i'
}

reg visitdum1 visitno* treatvisitno* i.areacode

plotbeta treatvisitno1|treatvisitno2|treatvisitno3|treatvisitno4|treatvisitno5|treatvisitno6|treatvisitno7|treatvisitno8|treatvisitno9|treatvisitno10, vertical xlab(1 2 3 4 5 6 7 8 9 10) xtitle("Timing") xlab(none, axis(2)) xtitle("", axis(2))


